package jsonTest;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.TypeReference;
import com.tarena.lbs.pojo.basic.vo.ArticleItemTag;
import org.junit.Test;

import java.util.List;
import java.util.Map;

public class JSONtest {

    @Test
    public void json2Map(){
        String mapJson="{\n" +
                "  \"电影\": [\n" +
                "    {\n" +
                "      \"tagCategoryName\": \"电影\",\n" +
                "      \"tagLibraryBO\": {\n" +
                "        \"id\": 43,\n" +
                "        \"tagType\": 93,\n" +
                "        \"tagTypeName\": null,\n" +
                "        \"tagName\": \"剧情\",\n" +
                "        \"tagCategory\": 103,\n" +
                "        \"tagCategoryName\": null,\n" +
                "        \"coding\": \"ba28bd9d-3655-4f18-1041-bc1c1f932b4c\",\n" +
                "        \"status\": 0,\n" +
                "        \"usageCount\": 0,\n" +
                "        \"tagDesc\": \"剧情推进\",\n" +
                "        \"visibisity\": 0,\n" +
                "        \"createAt\": \"2023-12-03 16:00:00\",\n" +
                "        \"updateAt\": \"2023-12-03 16:00:00\",\n" +
                "        \"userSelected\": null\n" +
                "      }\n" +
                "    },\n" +
                "    {\n" +
                "      \"tagCategoryName\": \"电影\",\n" +
                "      \"tagLibraryBO\": {\n" +
                "        \"id\": 44,\n" +
                "        \"tagType\": 93,\n" +
                "        \"tagTypeName\": null,\n" +
                "        \"tagName\": \"喜剧\",\n" +
                "        \"tagCategory\": 103,\n" +
                "        \"tagCategoryName\": null,\n" +
                "        \"coding\": \"ba28bd9d-3655-4f18-1041-bc1c1f932b4c\",\n" +
                "        \"status\": 0,\n" +
                "        \"usageCount\": 0,\n" +
                "        \"tagDesc\": \"喜剧电影\",\n" +
                "        \"visibisity\": 0,\n" +
                "        \"createAt\": \"2023-12-03 16:00:00\",\n" +
                "        \"updateAt\": \"2023-12-03 16:00:00\",\n" +
                "        \"userSelected\": null\n" +
                "      }\n" +
                "    }\n" +
                "  ],\n" +
                "  \"游记\": [\n" +
                "    {\n" +
                "      \"tagCategoryName\": \"游记\",\n" +
                "      \"tagLibraryBO\": {\n" +
                "        \"id\": 40,\n" +
                "        \"tagType\": 93,\n" +
                "        \"tagTypeName\": null,\n" +
                "        \"tagName\": \"日记\",\n" +
                "        \"tagCategory\": 102,\n" +
                "        \"tagCategoryName\": null,\n" +
                "        \"coding\": \"f90af398-f7f7-4ef2-bd2b-90a056bce8de\",\n" +
                "        \"status\": 0,\n" +
                "        \"usageCount\": 0,\n" +
                "        \"tagDesc\": \"旅行日记\",\n" +
                "        \"visibisity\": 0,\n" +
                "        \"createAt\": \"2023-12-03 16:00:00\",\n" +
                "        \"updateAt\": \"2023-12-03 16:00:00\",\n" +
                "        \"userSelected\": null\n" +
                "      }\n" +
                "    },\n" +
                "    {\n" +
                "      \"tagCategoryName\": \"游记\",\n" +
                "      \"tagLibraryBO\": {\n" +
                "        \"id\": 41,\n" +
                "        \"tagType\": 93,\n" +
                "        \"tagTypeName\": null,\n" +
                "        \"tagName\": \"趣闻\",\n" +
                "        \"tagCategory\": 102,\n" +
                "        \"tagCategoryName\": null,\n" +
                "        \"coding\": \"ba28bd9d-3655-4f18-9041-bc1c1f932b4c\",\n" +
                "        \"status\": 0,\n" +
                "        \"usageCount\": 0,\n" +
                "        \"tagDesc\": \"趣闻轶事\",\n" +
                "        \"visibisity\": 0,\n" +
                "        \"createAt\": \"2023-12-03 16:00:00\",\n" +
                "        \"updateAt\": \"2023-12-03 16:00:00\",\n" +
                "        \"userSelected\": null\n" +
                "      }\n" +
                "    }\n" +
                "  ]\n" +
                "}";
       com.alibaba.fastjson2.TypeReference<Map<String, List<ArticleItemTag>>>
               targetTypeReference=new TypeReference<Map<String, List<ArticleItemTag>>>() {};
        Map<String, List<ArticleItemTag>> resultMap
                = JSON.parseObject(mapJson, targetTypeReference);
        //循环map
        resultMap.forEach((k,v)->{
            System.out.println("key:"+k);
            v.forEach(item->{
                System.out.println("item:"+item);
            });
        });
    }
}
